<template>
<!--!advanced && md || 24-->
	<a-col :md="!advanced && theMd || 24" :sm="theSm " :xs="theXs" :lg="!advanced && theLg || 24" :xl="!advanced && theXl || 24" :xxl="!advanced && theXxl || 24" style="padding: 0 15px">
        <span class="table-page-search-submitButtons" :style="{ float: 'right', overflow: 'hidden',marginTop: '4px'} ">
            <slot />
            <a-button :disabled="theDisabled"  type="primary" @click="queryBtn">查询</a-button>
            <a-button :disabled="theDisabled" style="margin-left: 8px;" @click="clearBtn">重置</a-button>
            <a v-if="showAdvanced" @click="toggleAdvanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
            </a>
        </span>
    </a-col>
</template>
<script>
export default {
	name: 'ZhFormQuery',
	props: {
        span: Number,
        //≥768px
        md:{
            type: Number,
            default:undefined
        },
        //≥576px
        sm:{
            type: Number,
            default:undefined
        },
        //<576px
        xs:{
            type: Number,
            default:undefined
        },
        //≥992px
        lg:{
            type: Number,
            default:undefined
        },
        //≥1200px
        xl:{
            type: Number,
            default:undefined
        },
        //≥1600px
        xxl:{
            type: Number,
            default:undefined
        },
        value:{
            type: Boolean,
            default:false
        },
        //是否可点击按钮
        disabled:{
            type: Boolean,
            default:null
        },
        //是否显示 展开收缩图标
        showAdvanced:{
            type: Boolean,
            default:true
        },
    },
    data () {
        return {
            advanced:this.value,
            theSpan:this.getSpan(),
            theMd:this.getMd(),
            theSm:this.getSm(),
            theXs:this.getXs(),
            theLg:this.getLg(),
            theXl:this.getXl(),
            theXxl:this.getXxl(),
            mySpan:null,
            theDisabled:false,
        }
    },
    created(){
        if(this.disabled==null||this.disabled==undefined){
            this.getDisabled()
        }else{
            this.theDisabled=this.disabled
        }
    },
    watch:{
        disabled(val){
            if(val==null||val==undefined){
                this.getDisabled()
            }else{
                this.theDisabled=val
            }
        }
    },
    methods: {
        queryBtn() {
            this.$emit('queryClick');
        },
        clearBtn(data){
            let parent=data;
            if(!parent){
                parent=this.$parent
            }else{
                parent=parent.$parent
            }
            try {
              parent.resetFields()
              let model=parent.model
              Object.keys(model).forEach(key => {
                if(model[key]==null||model[key]==''){
                  model[key] = undefined
                }else{
                  if(Array.isArray(model[key] )){
                    if(model[key].length==1){
                      if(!model[key][0]){
                        model[key] = undefined
                      }
                    }
                  }
                }
              })
            } catch(e) {
                this.clearBtn(parent)
            }


        },
        toggleAdvanced(){
            let advanced=!this.advanced
            this.advanced=advanced
            this.$emit('input', advanced)
        },
        getDisabled(data){
            let disabled=null;
            let parent=null;
            if(data){
                parent=data.$parent;
            }else{
                parent=this.$parent;
            }
            if(parent){
                disabled=parent.disabled
                if(disabled==null||disabled==undefined){
                    this.getDisabled(parent)
                }else{
                    this.theDisabled=disabled
                }

            }else{
                this.theDisabled=false
            }
        },
         getSpan(data){
            if(this.span){
                this.mySpan=this.span
                return this.span
            }
            let span=null;
            let parent=null;
            if(data){
                parent=data.$parent;
            }else{
                parent=this.$parent;
            }
            if(parent){
                span=parent.span

                if(span==null||span==undefined){
                    let name=parent.$options.name
                    if(name=='ZhForm'){
                        this.mySpan=undefined
                        return undefined
                    }
                    return this.getSpan(parent)
                }else{
                    this.mySpan=span
                    return span
                }

            }else{
                this.mySpan=undefined
                return undefined
            }
        },
        getMd(data){
            if(this.mySpan){
                return undefined
            }else{
                this.getSpan()
            }
            if(this.md){
                return this.md
            }
            let md=null;
            let parent=null;
            if(data){
                parent=data.$parent;
            }else{
                parent=this.$parent;
            }
            if(parent){
                md=parent.md
                if(md==null||md==undefined){
                   return this.getMd(parent)
                }else{
                    return md
                }

            }else{
                return undefined
            }
        },
        getSm(data){
            if(this.mySpan){
                return undefined
            }else{
                this.getSpan()
            }
            if(this.sm){
                return this.sm
            }
            let sm=null;
            let parent=null;
            if(data){
                parent=data.$parent;
            }else{
                parent=this.$parent;
            }
            if(parent){
                sm=parent.sm
                if(sm==null||sm==undefined){
                   return this.getSm(parent)
                }else{
                    return sm
                }

            }else{
                return undefined
            }
        },
        getXs(data){
           if(this.mySpan){
                return undefined
            }else{
                this.getSpan()
            }
            if(this.xs){
                return this.xs
            }
            let xs=null;
            let parent=null;
            if(data){
                parent=data.$parent;
            }else{
                parent=this.$parent;
            }
            if(parent){
                xs=parent.xs
                if(xs==null||xs==undefined){
                   return this.getXs(parent)
                }else{
                    return xs
                }

            }else{
                return undefined
            }
        },
        getLg(data){
            if(this.mySpan){
                return undefined
            }else{
                this.getSpan()
            }
            if(this.lg){
                return this.lg
            }
            let lg=null;
            let parent=null;
            if(data){
                parent=data.$parent;
            }else{
                parent=this.$parent;
            }
            if(parent){
                lg=parent.lg
                if(lg==null||lg==undefined){
                   return this.getLg(parent)
                }else{
                    return lg
                }

            }else{
                return undefined
            }
        },
        getXl(data){
            if(this.mySpan){
                return undefined
            }else{
                this.getSpan()
            }
            if(this.xl){
                return this.xl
            }
            let xl=null;
            let parent=null;
            if(data){
                parent=data.$parent;
            }else{
                parent=this.$parent;
            }
            if(parent){
                xl=parent.xl
                if(xl==null||xl==undefined){
                   return this.getXl(parent)
                }else{
                    return xl
                }

            }else{
                return undefined
            }
        },
        getXxl(data){
           if(this.mySpan){
                return undefined
            }else{
                this.getSpan()
            }
            if(this.xxl){
                return this.xxl
            }
            let xxl=null;
            let parent=null;
            if(data){
                parent=data.$parent;
            }else{
                parent=this.$parent;
            }
            if(parent){
                xxl=parent.xxl
                if(xxl==null||xxl==undefined){
                   return this.getXxl(parent)
                }else{
                    return xxl
                }

            }else{
                return undefined
            }
        },
    }
}
</script>